package com.aaron.kjviewutils.today;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.aaron.kjviewutils.R;

import java.util.List;

import butterknife.Bind;
import butterknife.ButterKnife;

/**
 * Created by Aaron on 2017/3/6.
 */

public class TodayAdapter extends RecyclerView.Adapter<TodayAdapter.TodayViewHolder> {

    private List<TodayBean.TodayInner> datas;
    private Context context;

    public TodayAdapter(Context context, List<TodayBean.TodayInner> datas)
    {
        this.context = context;
        this.datas = datas;
    }

    @Override
    public TodayViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(context).inflate(R.layout.item_tody, parent, false);
        return new TodayViewHolder(view);
    }

    @Override
    public void onBindViewHolder(final TodayViewHolder holder, int position) {
        if(null!=datas&&!datas.isEmpty()&&null!=datas.get(position))
        {
            TodayBean.TodayInner today = datas.get(position);
            holder.title.setText(today.title);
            String year = today.date.substring(0, today.date.length()-4);
            holder.date.setText(year+"年"+today.month+"月"+today.day+"日");
            holder.event.setText(today.event);
        }
    }

    @Override
    public int getItemCount() {
        return (null==datas)?0:datas.size();
    }

    public class TodayViewHolder extends RecyclerView.ViewHolder
    {
        @Bind(R.id.title)
        TextView title;
        @Bind(R.id.date)
        TextView date;
        @Bind(R.id.event)
        TextView event;

        public TodayViewHolder(View itemView) {
            super(itemView);
            ButterKnife.bind(this, itemView);
        }
    }
}
